﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SilverTile;

namespace SilverTileTests
{
    [TestClass]
    public class CollisionEnumTests
    {
        [TestMethod]
        public void Collision_Should_Be_A_Flags_Enum_Where_All_Attribs_Can_Be_Set()
        {

            Collision collision = Collision.None;
            collision = collision | Collision.Top | Collision.Right | Collision.Bottom | Collision.Left;

            Assert.AreEqual(Collision.None, collision & Collision.None, "Collision.None should be set");
            Assert.AreEqual(Collision.Top, collision & Collision.Top, "Collision.Top should be set");
            Assert.AreEqual(Collision.Right, collision & Collision.Right, "Collision.Right should be set");
            Assert.AreEqual(Collision.Bottom, collision & Collision.Bottom, "Collision.Bottom should be set");
            Assert.AreEqual(Collision.Left, collision & Collision.Left, "Collision.Left should be set");

        }

        [TestMethod]
        public void Collision_Extension_Methods_Should_Replace_Boolean_Operations()
        {

            Collision collision = Collision.None;
            Assert.IsTrue(collision.IsSet(Collision.None), "Collision.None IsSet should return true");

            collision = collision.Set(Collision.Left).Clear(Collision.None);
            Assert.IsTrue(collision.IsSet(Collision.Left), "Collision.Left IsSet should return true");
            Assert.IsTrue(collision.IsNotSet(Collision.None), "Collision.None IsNotSet should return true");
            Assert.IsFalse(collision.IsNotSet(Collision.Left), "Collision.Left IsNotSet should return false");
            Assert.IsFalse(collision.IsSet(Collision.None), "Collision.None IsSet should return false");

            collision = collision.Set(Collision.Bottom);
            Assert.IsTrue(collision.IsSet(Collision.Left), "Collision.Left IsSet should return true");
            Assert.IsTrue(collision.IsNotSet(Collision.None), "Collision.None IsNotSet should return true");
            Assert.IsTrue(collision.IsSet(Collision.Bottom), "Collision.Bottom IsSet should return true");
                                    
        }

        [TestMethod]
        public void Collision_Collides_Syould_Return_True_For_Any_Collision()
        {

            Collision collision = Collision.None;
            Assert.IsFalse(collision.Collides(), "Collision.None should return false for Collides");

            collision = Collision.Top;
            Assert.IsTrue(collision.Collides(), "Collision.Top should return true for Collides");

            collision = Collision.Right;
            Assert.IsTrue(collision.Collides(), "Collision.Right should return true for Collides");

            collision = Collision.Bottom;
            Assert.IsTrue(collision.Collides(), "Collision.Bottom should return true for Collides");

            collision = Collision.Left;
            Assert.IsTrue(collision.Collides(), "Collision.Left should return true for Collides");

            collision = Collision.All;
            Assert.IsTrue(collision.Collides(), "Collision.All should return true for Collides");

            collision = Collision.Top | Collision.Right | Collision.Bottom | Collision.Left | Collision.None;
            Assert.IsTrue(collision.Collides(), "Combination of all collisions should return true for Collides");
            
        }

        [TestMethod]
        public void Collision_All_Should_Equal_All_Collisions_Except_None()
        {

            Collision combined = Collision.Top | Collision.Right | Collision.Bottom | Collision.Left;
            Collision all = Collision.All;

            Assert.AreEqual(combined, all, "Collision.All should equal all collisions combined");

            combined = Collision.None | Collision.Top | Collision.Right | Collision.Bottom | Collision.Left;
            Assert.AreNotEqual(combined, all, "Collision.All should not equal all collisions combined including None");

        }

        [TestMethod]
        public void Collision_IsAnySet_Should_Compare_Two_Collisions()
        {

            Collision coll1 = Collision.Left | Collision.Right;
            Collision coll2 = Collision.Top | Collision.Bottom;
            Collision coll3 = Collision.Left | Collision.Top;

            Assert.IsTrue(coll1.IsAnySet(coll3));
            Assert.IsFalse(coll1.IsAnySet(coll2));
            
        }

    }
}